package com.ry.demo.concurrent.demo.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: lihui
 * @Date: 2021-12-08 09:20
 * @Description:
 */
public class ReentrantTryLockDemo {

    public static void main(String[] args) throws InterruptedException {

        ReentrantLock reentrantLock = new ReentrantLock();
        reentrantLock.lock();

        Thread.sleep(1000);

        new Thread(()->{

            try {
                boolean lock = reentrantLock.tryLock(8, TimeUnit.SECONDS);
                if (lock){
                    System.out.println("获取到了锁");
                }else {
                    System.out.println("获取锁超时");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }).start();




    }

}
